<template>
  <a-descriptions :column="1" bordered>
    <a-descriptions-item label="机构名称">
      {{ model.departName || '-' }}
    </a-descriptions-item>
    <a-descriptions-item label="机构别称">
      {{ model.departNameAbbr || '-' }}
    </a-descriptions-item>
    <a-descriptions-item label="上级部门">
      {{ model.parentName || '-' }}
    </a-descriptions-item>
    <a-descriptions-item label="机构编码">
      {{ model.orgCode || '-' }}
    </a-descriptions-item>
    <a-descriptions-item label="机构类型">
      {{ model.departType || '-' }}
    </a-descriptions-item>
    <a-descriptions-item label="排序编号">
      {{ model.departOrder || '-' }}
    </a-descriptions-item>
    <a-descriptions-item label="手机号">
      {{ model.mobile || '-' }}
    </a-descriptions-item>
    <a-descriptions-item label="地址">
      {{ model.address || '-' }}
    </a-descriptions-item>
    <a-descriptions-item label="备注">
      {{ model.memo || '-' }}
    </a-descriptions-item>
  </a-descriptions>
</template>
<script>
import { queryIdTree, ajaxGetDictItems } from '@/api/api'

export default {
  name: 'DeptBaseInfo',
  data() {
    return {
      departTypeData: [],
      model: {},
      treeData: []
    }
  },
  created() {
    this.loadTreeData()
    this.initDictData()
  },
  methods: {
    loadTreeData() {
      queryIdTree().then((res) => {
        if (res.success) {
          for (let i = 0; i < res.result.length; i++) {
            const temp = res.result[i]
            this.treeData.push(temp)
          }
        }
      })
    },
    initDictData() {
      ajaxGetDictItems('org_category', null).then(res => {
        if (res.success) this.departTypeData = res.result
      })
    },
    open(record) {
      this.model = record
      if (this.model.parentId) this.transCode(this.model.parentId, 1, this.treeData)
      if (this.model.orgCategory) this.transCode(this.model.orgCategory, 2, this.departTypeData)
    },
    transCode(code, targetNumber, dictionary) {
      if (targetNumber === 1) {
        if (!this.model.parentName) {
          for (const item of dictionary) {
            if (item.value === code) {
              this.model.parentName = item.title
              break
            } else {
              this.transCode(code, targetNumber, item.children)
            }
          }
        }
      } else {
        if (!this.model.departType) {
          for (const item of dictionary) {
            if (item.value === code) {
              this.model.departType = item.title
              break
            }
          }
        }
      }
    },
    clearForm() {
      this.model = {}
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
::v-deep .ant-card-body {
  padding: 0 !important;
}
</style>
